package com.ruoyi.web.controller.sz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.system.domain.sz.SzLeaderGroupSnapshot;
import com.ruoyi.system.domain.sz.TimeLine;
import com.ruoyi.system.service.sz.ISzLeaderGroupService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.sz.SzLeaderGroup;

/**
 * 领导小组&密码办Controller
 * 
 * @author ruoyi
 * @date 2024-03-16
 */

@Anonymous
@RestController
@RequestMapping("/sz/group")
public class SzLeaderGroupController extends BaseController
{
    @Autowired
    private ISzLeaderGroupService szLeaderGroupService;

    /**
     * 查询领导小组&密码办列表
     */
//    @PreAuthorize("@ss.hasPermi('sz:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzLeaderGroup szLeaderGroup)
    {
        startPage();
        List<SzLeaderGroup> list = szLeaderGroupService.selectSzLeaderGroupList(szLeaderGroup);
        return getDataTable(list);
    }

    /**
     * 导出领导小组&密码办列表
     */
//    @PreAuthorize("@ss.hasPermi('sz:group:export')")
//    @Log(title = "领导小组&密码办", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzLeaderGroup szLeaderGroup)
    {
        List<SzLeaderGroup> list = szLeaderGroupService.selectSzLeaderGroupList(szLeaderGroup);
        ExcelUtil<SzLeaderGroup> util = new ExcelUtil<SzLeaderGroup>(SzLeaderGroup.class);
        util.exportExcel(response, list, "领导小组&密码办数据");
    }

    /**
     * 获取领导小组&密码办详细信息
     */
//    @PreAuthorize("@ss.hasPermi('sz:group:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return success(szLeaderGroupService.selectSzLeaderGroupByGroupId(groupId));
    }

    /**
     * 新增领导小组&密码办
     */
//    @PreAuthorize("@ss.hasPermi('sz:group:add')")
//    @Log(title = "领导小组&密码办", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzLeaderGroup szLeaderGroup)
    {
        return toAjax(szLeaderGroupService.insertSzLeaderGroup(szLeaderGroup));
    }

    /**
     * 新增领导小组&密码办
     */
//    @PreAuthorize("@ss.hasPermi('sz:snapshot:add')")
//    @Log(title = "领导小组&密码办", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult batch(@RequestBody TimeLine timeLine)
    {
        return toAjax(szLeaderGroupService.batchSzLeaderGroup(timeLine));
    }

//    @PreAuthorize("@ss.hasPermi('sz:snapshot:add')")
//    @Log(title = "领导小组&密码办", businessType = BusinessType.INSERT)
    @PostMapping("/check")
    public AjaxResult check(@RequestBody List<SzLeaderGroup> szLeaderGroups)
    {
        if(szLeaderGroupService.checkNumberAndName(szLeaderGroups)){
            return error("领导人员小组/密法办成员发生变化，将更新时间轴！");
        }
        return success();
    }

    /**
     * 修改领导小组&密码办
     */
//    @PreAuthorize("@ss.hasPermi('sz:group:edit')")
//    @Log(title = "领导小组&密码办", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzLeaderGroup szLeaderGroup)
    {
        return toAjax(szLeaderGroupService.updateSzLeaderGroup(szLeaderGroup));
    }

    /**
     * 删除领导小组&密码办
     */
//    @PreAuthorize("@ss.hasPermi('sz:group:remove')")
//    @Log(title = "领导小组&密码办", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(szLeaderGroupService.deleteSzLeaderGroupByGroupIds(groupIds));
    }
}
